<template>
  <div class="main">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/mamger' }"
        >数据统计</el-breadcrumb-item
      >
      <el-breadcrumb-item :to="{ path: '/reports' }"
        >数据报表</el-breadcrumb-item
      >
    </el-breadcrumb>

    <el-card class="box-card"> 

         <div id="cardBox"></div>

    </el-card>
  </div>
</template>

<script>


import { getCharts } from "../../api/index";
export default {
  name: "",
  data() {
    return {
      list: {},

      options: {
        title: {
          text: "用户来源",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#E9EEF3",
            },
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            boundaryGap: false,
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
      },
    };
  },
  
  mounted() {
    this.initGetChartsData();
   
  },
  methods: {
      // 解构赋值  
     //  1 左右结构一致  
    //   2 只要右边不是一个报错的代码    
    async initGetChartsData() {
      let {  data,meta: { status }} = await getCharts();
        console.log(data);
      if (status != 200) return this.$message.error("请求失败");
      this.list = data;// 获取到的对象
      this.options // 原来的对象
      
      let  newOptions={...this.options ,...data} // 合并对象

        //   this.initCharts(合并后的对象);
        this.initCharts(newOptions)
    },

    initCharts(options) {
      // 基于准备好的dom，初始化echarts实例
      var myChart = this.$echarts.init(document.getElementById("cardBox"));
      // 绘制图表
      myChart.setOption(options);
    },
  },
 
};
</script>

<style scoped lang="css">
.main {
  padding-left: 20px;
}

.box-card {
  width: 1200px;
}

#cardBox {
    width: 750px;
    height: 400px;
}
</style>
